package com.ctshk.rpc.goods.service.impl;

import com.ctshk.rpc.goods.dto.RegionalFreightDTO;
import org.apache.dubbo.config.annotation.DubboService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.rpc.goods.entity.RegionalFreight;
import com.ctshk.rpc.goods.mapper.RegionalFreightMapper;
import com.ctshk.rpc.goods.service.IRegionalFreightService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 地区运费表 服务实现类
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-09
 */
@DubboService
public class RegionalFreightServiceImpl extends ServiceImpl<RegionalFreightMapper, RegionalFreight> implements IRegionalFreightService {
    @Autowired
    RegionalFreightMapper regionalFreightMapper;

    @Override
    public List<RegionalFreightDTO> findRegionalFreightListByTemplateId(Long templateId) {
        List<RegionalFreight> regionalFreights = regionalFreightMapper.findBatchFreightByTemplateId(templateId);
        if(regionalFreights != null && regionalFreights.size() > 0){
            List<RegionalFreightDTO> regionalFreightDTOS = new ArrayList<>();
            regionalFreights.stream().forEach(item -> {
                RegionalFreightDTO regionalFreightDTO = new RegionalFreightDTO();
                BeanUtils.copyProperties(item, regionalFreightDTO);
                regionalFreightDTOS.add(regionalFreightDTO);
            });
            return regionalFreightDTOS;
        }
        return new ArrayList<>();
    }
}
